package pixelwaks.core.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;

import pixelwaks.core.IAnimation;
import pixelwaks.core.ISprite;

import common.core.Background;
import common.core.Scenery;
import common.plugin.IGameMode;

public class Game {

	private List<Player> players;
	private Background background;
	private Scenery scenery;
	public static int CURRENT_PLAYER = 0;
	private List<IAnimation> animations = new ArrayList<IAnimation>();
	private List<ISprite> sprites = new ArrayList<ISprite>();
	private Wind wind = new Wind();
	private IGameMode mode;
	private long benchmark;	

	public final static Semaphore lock = new Semaphore(1, true);

	private static Game game;

	public static Game getInstance() {
		if(game == null)
			game = new Game();
		return game;
	}	

	private Game() {
		benchmark();
	}
	
	// Extremely ugly benchmark
	private void benchmark() {
		long s = System.currentTimeMillis();
		String str;
		for(int i=0; i<100000000; i++) {
			if(i / 10 == 100)
				str = "d";
			else
				str = "e";
		}
		benchmark = System.currentTimeMillis()-s;
	}
	
	public int getBenchmarkValue() {
		int i = (int) benchmark;
		if(i <= 100)
			return 1;
		else if(i > 100 && i <= 150)
			return 5;
		else if(i > 150 && i <= 200)
			return 20;
		else if(i > 200 && i <= 250)
			return 30;
		else
			return 40;
	}

	public void addSprite(ISprite sprite) {
		sprites.add(sprite);
	}
	
	public List<ISprite> getISprites() {
		return sprites;
	}

	public void setWind(Wind wind) {
		this.wind = wind;
	}
	
	public Wind getWind() {
		return wind;
	}

	public void setBackground(Background background) {
		this.background = background;
	}
	
	public Background getBackground() {
		return background;
	}

	public void setScenery(Scenery scenery) {
		this.scenery = scenery;
	}
	
	public Scenery getScenery() {
		return scenery;
	}

	public void addAnimation(IAnimation animation) {
		animations.add(animation);
	}
	
	public List<IAnimation> getAnimations() {
		return animations;
	}
	
	public IAnimation getProjectile() {
		return animations.get(1);
	}
	
	public IAnimation getExplosion() {
		return animations.get(0);
	}
	
	public void setPlayers(List<Player> players) {
		this.players = players;
	}
	
	public List<Player> getPlayers() {
		return players;
	}
	
	public Player getCurrentPlayer() {
		return players.get(CURRENT_PLAYER);
	}
	
	public void setMode(IGameMode mode) {
		this.mode = mode;
	}
	
	public IGameMode getMode() {
		return mode;
	}
}
